SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
	CREATE TABLE [GOOGLECODERS].[Tarjetas](
	[IdTarjeta] [int] NOT NULL Identity(1,1),
	[NumeroTarjeta] [int] NOT NULL,
	[FechaAlta] [datetime] NOT NULL,
	[IdCliente] [int] NOT NULL,
	[Credito] [float] DEFAULT 0.0,
	[Habilitado] [bit] NOT NULL,
	UNIQUE (NumeroTarjeta)
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF

ALTER TABLE [GOOGLECODERS].[Tarjetas] ADD
	CONSTRAINT PK_tTarjetas PRIMARY KEY (IdTarjeta),
	CONSTRAINT FK_tCliente FOREIGN KEY (IdCliente)
		REFERENCES [GOOGLECODERS].[Clientes] (IdCliente);
GO

INSERT INTO [GOOGLECODERS].[Tarjetas]
SELECT DISTINCT
	tm.[TARJETA_NRO],
	tm.[TARJETA_FECHA_ALTA],
	c.[IdCliente],
	0.0,
	1
FROM [gd_eschema].[Maestra] tm,
	[GOOGLECODERS].[Clientes] c
WHERE
	tm.[CLIENTE_DNI]  = C.DNI